package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.RequestPath;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("adminCategoryController")
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类相关接口")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    @Autowired
    private DishService dishService;
    @Autowired
    private SetmealService setmealService;
    @GetMapping("/page")
    @ApiOperation("分类分页查询接口")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分类分页查询，参数：{}", categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
    @PostMapping
    @ApiOperation("新增分类接口")
    public Result save(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类，参数：{}", categoryDTO);
        categoryService.save(categoryDTO);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation("删除分类接口")
    public Result delete(Long id){
        log.info("删除分类，id为：{}", id);

        categoryService.delete(id);
        return Result.success();
    }
    @PutMapping
    @ApiOperation("修改分类接口")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类，参数：{}", categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("起售、停售分类接口")
    public Result startorstop(@PathVariable("status") Integer status, Long id){
            categoryService.startorstop(status, id);
            return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation("查询分类接口")
    public Result list(int type){
        log.info("查询分类，type为：{}", type);
        return Result.success(categoryService.list(type));
    }

}
